<template>
	<view class="last-result">
		<text style="font-size: 20px;font-weight: 700;">回答情况</text>
		<view class="">
			<u-collapse>
				<u-collapse-item :title="'专家'+(index+1)" :accordion="false" v-for="(item, index) in roundList" :key="item.id">
					<view>最大值：{{item.max_value}} —— 原因：{{item.max_reason}}</view>
					<view>最可能值：{{item.possible_value}} —— 原因：{{item.possible_reason}}</view>
					<view>最小值：{{item.min_value}} —— 原因：{{item.min_reason}}</view>
					<view>
						<view class="" v-for="result in item.config_result" :key="result">
							{{result}}
						</view>
					</view>
				</u-collapse-item>
			</u-collapse>
		</view>
		<view class="result_table">
			<u-table>
				<u-tr>
					<u-th>轮次</u-th>
					<u-th>最大值平均值(¥)</u-th>
					<u-th>最可能值平均值(¥)</u-th>
					<u-th>最小值平均值(¥)</u-th>
					<u-th>加权平均值(¥)</u-th>
				</u-tr>
				<u-tr v-for="item in resultList" :key="item.id">
					<u-td>{{item.result_round}}</u-td>
					<u-td>{{item.max_average.toFixed(2)}}</u-td>
					<u-td>{{item.possible_average.toFixed(2)}}</u-td>
					<u-td>{{item.min_average.toFixed(2)}}</u-td>
					<u-td>{{item.estimate.toFixed(2)}}</u-td>
				</u-tr>
			</u-table>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				roundList: [], // 上轮回答情况
				resultList: [], // 上轮回答结果
			}
		},
		mounted() {
			this.initData()
		},
		props: {
			questionId: {
				type: Number
			},
			round: {
				type: Number
			},
		},
		methods: {
			initData() {
				// 查看当前问卷上一轮所有回答情况
				if (this.round >= 2)
					this.$u.api.roundAnswerList({
						round: this.round - 1,
						question_id: this.questionId
					}).then(res => {
						this.roundList = res.data.list.map(it => {
							return {
								...it,
								config_result: JSON.parse(it.config_result)
							}
						})
					})
				this.$u.api.resultList({
					question_id: this.questionId
				}).then(res => {
					this.resultList = res.data.list
					console.log(this.resultList);
				})
			}
		}
	}
</script>

<style scope lang="scss">
	.last-result {
		.result_table {
			margin: 6rpx;
		}
	}
</style>
